/**
 * 提料详情
 * Created by Wayne on 2015/7/15.
 */

define(function(require, exports, module) {
    'use strict';
    module.exports = function(app) {
        app.register.controller('FeedDetailCtrl', ['$rootScope', '$scope', 'MHService', '$routeParams','$location', 'tempData',
        function($rootScope, $scope, MHService, $routeParams, $location, tempData) {
            // $scope.URL = MHService.URL.feedManage + '?id=' + $routeParams['Id'];
            var toast = require('../services/mh-toast');
            if($rootScope.repeat==undefined) {
                $location.path('/feedManage');
                return;
            }
            $scope.title = '提料 ' + $location.search().name;
            var Id = $routeParams['Id'];
            for(var i=0;i<$rootScope.repeat.length;i++) {
                if($rootScope.repeat[i].id == Id) {
                    $scope.feed = $rootScope.repeat[i];
                }
            }
            //展开提料列表
            $scope.show = function(index) {
                // angular.element('#'+ index).css({'bgcolor': 'red'});
                // console.log(angular.element('#'+ index));
                if($scope.detail == index) {
                    $scope.detail = null;
                } else {
                    $scope.detail = index;
                }
            }
            //取消申请
            $scope.cancelReq = function() {
                var config = {
                    url: MHService.URL.cancel_req,
                    _req: {
                        id: $scope.feed.id
                    }
                };
                MHService.postReq(config, function(res) {
                    // console.log(data);
                    if(res.data==1) {
                        toast.show('取消成功');
                    } else {
                        toast.show('流程已经开始，无法取消.')
                    }
                })
            }
            //入库验收
            $scope.warehouse = function(index, storage_status) {
                if(storage_status!==-1) {
                    toast.show('SOMETHING WAS WRONG! -warehouse');
                    return;
                }
                $scope.feed.mmsIndex = index;
                tempData.data = $scope.feed;
                $location.path('/warehouse');
                // ?count='+ $scope.feed.mms[index].material.count
                // +'&unit=' + $scope.feed.mms[index].material.unit
                // +'&name=' + $scoep.feed.mms[index].material.name
            }
            //填写苗木档案
            $scope.record = function(index, classid, resolveid, name) {
                var resolveid = resolveid;
                if(classid!=='精品植物') {
                    toast.show('SOMETHING WAS WRONG! -record');
                    return;
                }
                $location.path('/record/' + resolveid +'&' + name);
            }
        }])
    }
})